/* fifo_seqnum.h

   Header file used by fifo_seqnum_server.c and fifo_seqnum_client.c

   These programs create FIFOS in /tmp. This makes it easy to compile and
   run the programs. However, for a security reasons, a real-world
   application should never create sensitive files in /tmp. (As a simple of
   example of the kind of security problems that can result, a malicious
   user could create a FIFO using the name defined in SERVER_FIFO, and
   thereby cause a denial of service attack against this application.
   See Section 38.7 of "The Linux Programming Interface" for more details
   on this subject.)
*/
#ifndef _FIFO_SEQNUM_H
#define _FIFO_SEQNUM_H
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

/* Well-known name for server's FIFO */
#define SERVER_FIFO "/tmp/seqnum_sv"

/* Template for building client FIFO name */
#define CLIENT_FIFO_TEMPLATE "/tmp/seqnum_cl.%ld"

/* Space required for client FIFO pathname
  (+20 as a generous allowance for the PID) */
#define CLIENT_FIFO_NAME_LEN (sizeof(CLIENT_FIFO_TEMPLATE) + 20)

struct request { /* Request (client --> server) */
  pid_t pid;     /* PID of client */
  int seqLen;    /* Length of desired sequence */
};

struct response { /* Response (server --> client) */
  int seqNum;     /* Start of sequence */
};
#endif